/*     */ package com.umeng.common.net;
/*     */ 
/*     */ import android.content.Context;
/*     */ import android.graphics.Bitmap;
/*     */ import android.graphics.Bitmap.Config;
/*     */ import android.graphics.Canvas;
/*     */ import android.graphics.Paint;
/*     */ import android.graphics.PorterDuff.Mode;
/*     */ import android.graphics.PorterDuffXfermode;
/*     */ import android.graphics.Rect;
/*     */ import android.graphics.RectF;
/*     */ import android.graphics.drawable.BitmapDrawable;
/*     */ import android.graphics.drawable.Drawable;
/*     */ import android.os.AsyncTask;
/*     */ import android.os.Environment;
/*     */ import android.view.animation.Animation;
/*     */ import android.widget.ImageView;
/*     */ import com.umeng.common.Log;
/*     */ import com.umeng.common.b;
/*     */ import com.umeng.common.util.h;
/*     */ import java.io.File;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.lang.reflect.InvocationTargetException;
/*     */ import java.lang.reflect.Method;
/*     */ import java.net.URL;
/*     */ import java.net.URLConnection;
/*     */ import java.util.Collections;
/*     */ import java.util.Date;
/*     */ import java.util.Map;
/*     */ import java.util.Stack;
/*     */ import java.util.WeakHashMap;
/*     */ 
/*     */ public class q
/*     */ {
/*  49 */   private static final String b = q.class.getName();
/*     */ 
/*  55 */   public static boolean a = false;
/*     */   private static final long c = 52428800L;
/*     */   private static final long d = 10485760L;
/*     */   private static final long e = 1800000L;
/*  73 */   private static final Map<ImageView, String> f = Collections.synchronizedMap(new WeakHashMap());
/*     */   private static Thread g;
/*     */ 
/*     */   private static String b(String paramString)
/*     */   {
/*  87 */     int i = paramString.lastIndexOf(".");
/*  88 */     String str = "";
/*  89 */     if (i >= 0) {
/*  90 */       str = paramString.substring(i);
/*     */     }
/*  92 */     return h.a(paramString) + str;
/*     */   }
/*     */ 
/*     */   public static String a(Context paramContext, String paramString)
/*     */   {
/* 120 */     if (h.d(paramString)) return null;
/*     */ 
/* 122 */     File localFile1 = null;
/*     */     try {
/* 124 */       String str1 = b(paramString) + ".tmp";
/*     */       String str2;
/*     */       long l;
/* 129 */       if (b.b()) {
/* 130 */         str2 = Environment.getExternalStorageDirectory().getCanonicalPath();
/* 131 */         l = 52428800L;
/*     */       } else {
/* 133 */         str2 = paramContext.getCacheDir().getCanonicalPath();
/* 134 */         l = 10485760L;
/*     */       }
/*     */ 
/* 137 */       File localFile2 = new File(str2 + "/download/.um");
/*     */ 
/* 139 */       a(localFile2, l, 1800000L);
/*     */ 
/* 141 */       localFile1 = new File(localFile2, str1);
/* 142 */       localFile1.createNewFile();
/* 143 */       FileOutputStream localFileOutputStream = new FileOutputStream(localFile1);
/*     */ 
/* 145 */       InputStream localInputStream = (InputStream)new URL(paramString).openConnection().getContent();
/*     */ 
/* 147 */       byte[] arrayOfByte = new byte[4096];
/*     */       int i;
/* 149 */       while ((i = localInputStream.read(arrayOfByte)) != -1) {
/* 150 */         localFileOutputStream.write(arrayOfByte, 0, i);
/*     */       }
/* 152 */       localFileOutputStream.flush();
/*     */ 
/* 154 */       localInputStream.close();
/* 155 */       localFileOutputStream.close();
/*     */ 
/* 157 */       File localFile3 = new File(localFile1.getParent(), localFile1.getName().replace(".tmp", ""));
/* 158 */       localFile1.renameTo(localFile3);
/* 159 */       Log.a(b, "download img[" + paramString + "]  to " + localFile3.getCanonicalPath());
/* 160 */       return localFile3.getCanonicalPath();
/*     */     } catch (Exception localException) {
/* 162 */       Log.a(b, localException.getStackTrace().toString() + "\t url:\t" + 
/* 163 */         h.a + paramString);
/* 164 */       if ((localFile1 != null) && (localFile1.exists()))
/* 165 */         localFile1.deleteOnExit();
/*     */     }
/* 167 */     return null;
/*     */   }
/*     */ 
/*     */   public static File a(String paramString, Context paramContext, boolean[] paramArrayOfBoolean)
/*     */     throws IOException
/*     */   {
/* 181 */     if (b.b()) {
/* 182 */       str = Environment.getExternalStorageDirectory().getCanonicalPath();
/* 183 */       str = str + "/download/.um" + paramString;
/* 184 */       localFile = new File(str);
/* 185 */       localFile.mkdirs();
/* 186 */       if (localFile.exists()) {
/* 187 */         paramArrayOfBoolean[0] = true;
/* 188 */         return localFile;
/*     */       }
/*     */     }
/* 191 */     String str = paramContext.getCacheDir().getAbsolutePath();
/* 192 */     new File(str).mkdir();
/* 193 */     a(str, 505, -1, -1);
/* 194 */     str = str + "/umdownload";
/* 195 */     new File(str).mkdir();
/* 196 */     a(str, 505, -1, -1);
/* 197 */     File localFile = new File(str);
/* 198 */     paramArrayOfBoolean[0] = false;
/* 199 */     return localFile;
/*     */   }
/*     */ 
/*     */   public static boolean a(String paramString, int paramInt1, int paramInt2, int paramInt3)
/*     */   {
/*     */     try
/*     */     {
/* 212 */       Class localClass = Class.forName("android.os.FileUtils");
/* 213 */       Method localMethod = localClass.getMethod("setPermissions", new Class[] { String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE });
/* 214 */       localMethod.invoke(null, new Object[] { paramString, Integer.valueOf(paramInt1), Integer.valueOf(-1), Integer.valueOf(-1) });
/* 215 */       return true;
/*     */     } catch (ClassNotFoundException localClassNotFoundException) {
/* 217 */       Log.b(b, "error when set permissions:", localClassNotFoundException);
/*     */     } catch (NoSuchMethodException localNoSuchMethodException) {
/* 219 */       Log.b(b, "error when set permissions:", localNoSuchMethodException);
/*     */     } catch (IllegalArgumentException localIllegalArgumentException) {
/* 221 */       Log.b(b, "error when set permissions:", localIllegalArgumentException);
/*     */     } catch (IllegalAccessException localIllegalAccessException) {
/* 223 */       Log.b(b, "error when set permissions:", localIllegalAccessException);
/*     */     } catch (InvocationTargetException localInvocationTargetException) {
/* 225 */       Log.b(b, "error when set permissions:", localInvocationTargetException);
/*     */     }
/* 227 */     return false;
/*     */   }
/*     */ 
/*     */   public static boolean a(String paramString, int paramInt)
/*     */   {
/* 232 */     int i = 432;
/*     */ 
/* 234 */     if ((paramInt & 0x1) != 0) {
/* 235 */       i |= 4;
/*     */     }
/* 237 */     if ((paramInt & 0x2) != 0) {
/* 238 */       i |= 2;
/*     */     }
/* 240 */     return a(paramString, i, -1, -1);
/*     */   }
/*     */ 
/*     */   public static void a(File paramFile, long paramLong1, long paramLong2)
/*     */     throws IOException
/*     */   {
/* 251 */     if (paramFile.exists()) {
/* 252 */       if (a(paramFile.getCanonicalFile()) > paramLong1) {
/* 253 */         File localFile = paramFile;
/* 254 */         if (g == null) {
/* 255 */           g = new Thread(new r(localFile, paramLong2));
/*     */         }
/*     */ 
/* 263 */         synchronized (g) {
/* 264 */           g.start();
/*     */         }
/*     */       }
/*     */     }
/* 268 */     else if (!paramFile.mkdirs())
/*     */     {
/* 270 */       Log.b(b, 
/* 271 */         "Failed to create directory" + 
/* 272 */         paramFile.getAbsolutePath() + 
/* 273 */         ". Check permission. Make sure WRITE_EXTERNAL_STORAGE is added in your Manifest.xml");
/*     */     }
/*     */   }
/*     */ 
/*     */   private static long a(File paramFile)
/*     */   {
/* 279 */     if ((paramFile == null) || (!paramFile.exists()) || (!paramFile.isDirectory())) return 0L;
/* 280 */     long l = 0L;
/*     */ 
/* 282 */     Stack localStack = new Stack();
/* 283 */     localStack.clear();
/*     */ 
/* 285 */     localStack.push(paramFile);
/*     */     int j;
/*     */     int i;
/* 287 */     for (; !localStack.isEmpty(); 
/* 291 */       i < j)
/*     */     {
/* 288 */       File localFile1 = (File)localStack.pop();
/*     */ 
/* 290 */       File[] arrayOfFile1 = localFile1.listFiles();
/*     */       File[] arrayOfFile2;
/* 291 */       j = (arrayOfFile2 = arrayOfFile1).length; i = 0; continue; File localFile2 = arrayOfFile2[i];
/*     */ 
/* 293 */       if (!localFile2.isDirectory())
/* 294 */         l += localFile2.length();
/* 291 */       i++;
/*     */     }
/*     */ 
/* 298 */     return l;
/*     */   }
/*     */ 
/*     */   private static void b(File paramFile, long paramLong)
/*     */   {
/* 308 */     if ((paramFile == null) || (!paramFile.exists()) || (!paramFile.canWrite()) || (!paramFile.isDirectory())) return;
/* 309 */     File[] arrayOfFile1 = paramFile.listFiles();
/* 310 */     for (File localFile : arrayOfFile1)
/* 311 */       if ((!localFile.isDirectory()) && 
/* 312 */         (new Date().getTime() - localFile.lastModified() > paramLong))
/* 313 */         localFile.delete();
/*     */   }
/*     */ 
/*     */   protected static File b(Context paramContext, String paramString)
/*     */     throws IOException
/*     */   {
/* 326 */     String str1 = b(paramString);
/*     */     String str2;
/* 329 */     if (b.b())
/* 330 */       str2 = Environment.getExternalStorageDirectory().getCanonicalPath();
/*     */     else {
/* 332 */       str2 = paramContext.getCacheDir().getCanonicalPath();
/*     */     }
/* 334 */     File localFile1 = new File(str2 + "/download/.um");
/*     */ 
/* 336 */     File localFile2 = new File(localFile1, str1);
/* 337 */     if (localFile2.exists()) return localFile2;
/*     */ 
/* 340 */     return null;
/*     */   }
/*     */ 
/*     */   public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean)
/*     */   {
/* 357 */     a(paramContext, paramImageView, paramString, paramBoolean, null, null, false);
/*     */   }
/*     */ 
/*     */   public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean, a parama)
/*     */   {
/* 374 */     a(paramContext, paramImageView, paramString, paramBoolean, parama, null, false);
/*     */   }
/*     */ 
/*     */   public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean, a parama, Animation paramAnimation)
/*     */   {
/* 393 */     a(paramContext, paramImageView, paramString, paramBoolean, parama, null, false);
/*     */   }
/*     */ 
/*     */   public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean1, a parama, Animation paramAnimation, boolean paramBoolean2)
/*     */   {
/* 413 */     if (paramImageView == null) return;
/* 414 */     f.put(paramImageView, paramString);
/*     */     try
/*     */     {
/* 417 */       File localFile = b(paramContext, paramString);
/*     */       Object localObject;
/* 418 */       if ((localFile != null) && (localFile.exists()) && (!a)) {
/* 419 */         if (parama != null) parama.a(b.a);
/* 420 */         localObject = c(localFile.getAbsolutePath());
/* 421 */         if (localObject == null)
/* 422 */           localFile.delete();
/* 423 */         b(paramContext, paramImageView, (Drawable)localObject, paramBoolean1, parama, paramAnimation, 
/* 424 */           paramBoolean2, paramString);
/*     */       } else {
/* 426 */         localObject = new c(paramContext, paramImageView, paramString, b.b, null, 
/* 427 */           paramBoolean1, parama, paramAnimation, paramBoolean2);
/* 428 */         ((c)localObject).execute(new Object[0]);
/*     */       }
/*     */     } catch (Exception localException) {
/* 431 */       Log.b(b, "", localException);
/* 432 */       if (parama != null) parama.a(p.a.b);
/*     */     }
/*     */   }
/*     */ 
/*     */   private static boolean a(ImageView paramImageView, String paramString)
/*     */   {
/* 443 */     String str = (String)f.get(paramImageView);
/* 444 */     if ((str != null) && (!str.equals(paramString)))
/* 445 */       return true;
/* 446 */     return false;
/*     */   }
/*     */ 
/*     */   private static synchronized void b(Context paramContext, ImageView paramImageView, Drawable paramDrawable, boolean paramBoolean1, a parama, Animation paramAnimation, boolean paramBoolean2, String paramString)
/*     */   {
/*     */     try
/*     */     {
/* 453 */       if ((paramBoolean2) && (paramDrawable != null)) {
/* 454 */         Bitmap localBitmap1 = ((BitmapDrawable)paramDrawable).getBitmap();
/* 455 */         Bitmap localBitmap2 = a(localBitmap1);
/* 456 */         paramDrawable = new BitmapDrawable(localBitmap2);
/*     */       }
/*     */ 
/* 459 */       if ((paramDrawable == null) || (paramImageView == null)) {
/* 460 */         if (parama != null) parama.a(p.a.b);
/* 461 */         Log.e(b, "bind drawable failed. drawable [" + paramDrawable + "]  imageView[+" + paramImageView + 
/* 462 */           "+]");
/* 463 */         return;
/*     */       }
/*     */ 
/* 466 */       if (a(paramImageView, paramString)) {
/* 467 */         if (parama != null) parama.a(p.a.b);
/* 468 */         return;
/*     */       }
/*     */ 
/* 471 */       if (paramBoolean1)
/* 472 */         paramImageView.setBackgroundDrawable(paramDrawable);
/*     */       else {
/* 474 */         paramImageView.setImageDrawable(paramDrawable);
/*     */       }
/* 476 */       if (paramAnimation != null) paramImageView.startAnimation(paramAnimation);
/*     */ 
/* 478 */       if (parama != null) parama.a(p.a.a); 
/*     */     }
/* 480 */     catch (Exception localException) { Log.b(b, "bind failed", localException);
/* 481 */       if (parama != null) parama.a(p.a.b);
/*     */     }
/*     */   }
/*     */ 
/*     */   private static Drawable c(String paramString)
/*     */   {
/* 566 */     Drawable localDrawable = null;
/*     */     try {
/* 568 */       localDrawable = Drawable.createFromPath(paramString);
/*     */     } catch (OutOfMemoryError localOutOfMemoryError) {
/* 570 */       Log.e(b, "Resutil fetchImage OutOfMemoryError:" + localOutOfMemoryError.toString());
/*     */     }
/* 572 */     return localDrawable;
/*     */   }
/*     */ 
/*     */   private static Bitmap a(Bitmap paramBitmap)
/*     */   {
/*     */     try
/*     */     {
/* 612 */       Bitmap localBitmap = Bitmap.createBitmap(paramBitmap.getWidth(), paramBitmap.getHeight(), 
/* 613 */         Bitmap.Config.ARGB_8888);
/* 614 */       Canvas localCanvas = new Canvas(localBitmap);
/*     */ 
/* 616 */       int i = -12434878;
/* 617 */       Paint localPaint = new Paint();
/* 618 */       Rect localRect = new Rect(0, 0, paramBitmap.getWidth(), paramBitmap.getHeight());
/* 619 */       RectF localRectF = new RectF(localRect);
/*     */ 
/* 621 */       localPaint.setAntiAlias(true);
/* 622 */       localCanvas.drawARGB(0, 0, 0, 0);
/* 623 */       localPaint.setColor(-12434878);
/*     */ 
/* 627 */       localCanvas.drawRoundRect(localRectF, paramBitmap.getWidth() / 6, paramBitmap.getHeight() / 6, localPaint);
/*     */ 
/* 629 */       localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
/* 630 */       localCanvas.drawBitmap(paramBitmap, localRect, localRect, localPaint);
/*     */ 
/* 632 */       paramBitmap.recycle();
/* 633 */       return localBitmap;
/*     */     } catch (OutOfMemoryError localOutOfMemoryError) {
/* 635 */       Log.e(b, "Cant`t create round corner bitmap. [OutOfMemoryError] ");
/* 636 */     }return null;
/*     */   }
/*     */ 
/*     */   public static abstract interface a
/*     */   {
/*     */     public abstract void a(q.b paramb);
/*     */ 
/*     */     public abstract void a(p.a parama);
/*     */   }
/*     */ 
/*     */   public static enum b
/*     */   {
/*     */   }
/*     */ 
/*     */   static class c extends AsyncTask<Object, Integer, Drawable>
/*     */   {
/*     */     private Context a;
/*     */     private String b;
/*     */     private ImageView c;
/*     */     private q.b d;
/*     */     private boolean e;
/*     */     private q.a f;
/*     */     private Animation g;
/*     */     private boolean h;
/*     */     private File i;
/*     */ 
/*     */     public c(Context paramContext, ImageView paramImageView, String paramString, q.b paramb, File paramFile, boolean paramBoolean1, q.a parama, Animation paramAnimation, boolean paramBoolean2)
/*     */     {
/* 506 */       this.i = paramFile;
/* 507 */       this.a = paramContext;
/* 508 */       this.b = paramString;
/* 509 */       this.f = parama;
/* 510 */       this.d = paramb;
/* 511 */       this.e = paramBoolean1;
/* 512 */       this.g = paramAnimation;
/* 513 */       this.c = paramImageView;
/* 514 */       this.h = paramBoolean2;
/*     */     }
/*     */ 
/*     */     protected void onPreExecute()
/*     */     {
/* 519 */       super.onPreExecute();
/* 520 */       if (this.f != null)
/* 521 */         this.f.a(this.d);
/*     */     }
/*     */ 
/*     */     protected void a(Drawable paramDrawable)
/*     */     {
/* 527 */       q.a(this.a, this.c, paramDrawable, this.e, this.f, this.g, this.h, this.b);
/*     */     }
/*     */ 
/*     */     protected Drawable a(Object[] paramArrayOfObject)
/*     */     {
/* 533 */       if (q.a)
/*     */         try {
/* 535 */           Thread.sleep(3000L);
/*     */         } catch (InterruptedException localInterruptedException) {
/* 537 */           localInterruptedException.printStackTrace();
/*     */         }
/*     */       Object localObject;
/* 541 */       if ((this.i != null) && (this.i.exists())) {
/* 542 */         localObject = q.a(this.i.getAbsolutePath());
/* 543 */         if (localObject == null)
/* 544 */           this.i.delete();
/* 545 */         Log.c(q.a(), "get drawable from cacheFile.");
/* 546 */         return localObject;
/*     */       }
/*     */       try {
/* 549 */         q.a(this.a, this.b);
/* 550 */         localObject = null;
/* 551 */         Drawable localDrawable = null;
/* 552 */         localObject = q.b(this.a, this.b);
/* 553 */         if ((localObject != null) && (((File)localObject).exists())) localDrawable = q.a(((File)localObject)
/* 554 */             .getAbsolutePath());
/* 555 */         Log.c(q.a(), "get drawable from net else file.");
/* 556 */         return localDrawable;
/*     */       } catch (Exception localException) {
/* 558 */         Log.e(q.a(), localException.toString(), localException);
/*     */       }
/*     */ 
/* 561 */       return null;
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.common.net.q
 * JD-Core Version:    0.6.2
 */